﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties.CApSLPSetLocationsPropertiesLocationValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties;

internal class CApSLPSetLocationsPropertiesLocationValidator : ITxValidator
{
  private ITxRobotController _commonController;

  public CApSLPSetLocationsPropertiesLocationValidator(ITxRobotController controller)
  {
    this._commonController = controller;
  }

  public ITxObject GetObject(string str)
  {
    ITxObject itxObject1 = (ITxObject) null;
    if (!string.IsNullOrEmpty(str))
    {
      TxObjectList objectsByName = TxApplication.ActiveDocument.GetObjectsByName(str);
      if (objectsByName != null && ((Collection<ITxObject>) objectsByName).Count > 0)
      {
        foreach (ITxObject itxObject2 in (Collection<ITxObject>) objectsByName)
        {
          if (itxObject2 != null && itxObject2 is ITxRoboticLocationOperation)
          {
            itxObject1 = itxObject2;
            break;
          }
        }
      }
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = string.Empty;
    if (obj != null)
      text = obj.Name;
    return text;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    bool flag = false;
    errorMessage = StringTable.ResourceManager.GetString("SLP_Location_Error");
    ITxRobotController controller = CApSLPSetLocationsPropertiesLogic.GetController(obj as ITxRoboticLocationOperation);
    if (obj != null && obj is ITxRoboticLocationOperation && this._commonController != null && controller != null)
    {
      flag = controller.Name == this._commonController.Name && (!(controller is ITxRobotRRSController) || !(this._commonController is ITxRobotRRSController) || (controller as ITxRobotRRSController).Version == (this._commonController as ITxRobotRRSController).Version);
      if (!flag)
        errorMessage = StringTable.ResourceManager.GetString("SLP_Location_Controller_Error");
    }
    if (flag)
      errorMessage = (string) null;
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    return this.IsValidObject(this.GetObject(text), out errorMessage);
  }
}
